package hufs.cskim.media;

import java.util.ArrayList;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PlayListAdapter extends BaseAdapter {

	private ArrayList<MusicInfo> list;
	private LayoutInflater layout;
	private int resId;
	
	public PlayListAdapter(Context c, int resourceId, ArrayList<MusicInfo> _list){
		list = _list;
		layout = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		resId = resourceId;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		if(arg1 == null){
			arg1 = layout.inflate(resId, arg2, false);
		}
		
		ImageView img = (ImageView) arg1.findViewById(R.id.album_art);
		TextView title = (TextView) arg1.findViewById(R.id.title);
		TextView artist = (TextView) arg1.findViewById(R.id.artist);
		
		if(list.get(arg0).getImg() != null)
			img.setImageURI(Uri.parse(list.get(arg0).getImg()));
		
		title.setText(list.get(arg0).getTitle());
		artist.setText(list.get(arg0).getArtist());
		
		return arg1;
	}

}
